package com.corpdata.activiti.service;

import java.util.List;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

@Service
public class ActivitiService {
	
	@Autowired
	private RuntimeService runtimeService;
	@Autowired
	ProcessEngine processEngine;
	@Autowired
	private TaskService taskService;
	@Autowired
	private RepositoryService repositoryService;
	
	/**
	 * 获取用户任务列表
	 * @param userId
	 * @return
	 */
	public String getAllTasks(String userId){
		String jsonData = "";
		List<Task> list = taskService.createTaskQuery().list();
		for(Task task : list){
			System.out.println(task.getId());
			System.out.println(task.getAssignee());
			System.out.println(task.getName());
		}
		jsonData = JSON.toJSONStringWithDateFormat(list,"yyyy-MM-dd");
		return jsonData;
	}
	
	/**
	 * 获取所有已部署流程
	 * @return
	 */
	public String getAllDeploymentProcess(){
		
		System.out.println(this.getClass().getClassLoader().toString());
		
		String jsonData = "";
		List<Deployment> list =repositoryService.createDeploymentQuery().list();
		for(Deployment dep : list){
			//jsonData = JSON.toJSONString(list);
			System.out.println(dep.getId());
			System.out.println(dep.getName());
			System.out.println(dep.getDeploymentTime());
			System.out.println(dep.getCategory());
		}
		jsonData = JSON.toJSONStringWithDateFormat(list,"yyyy-MM-dd");
		
		return jsonData;
	}
}
